<?xml version="1.0" encoding="ISO-8859-1" ?>

<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:rich="http://richfaces.org/rich"
	  xmlns:a4j="http://richfaces.org/a4j"
	  xmlns:easy="http://easyfaces.com.br/easyfaces"
	  xmlns:c="http://java.sun.com/jstl/core">
	
	<f:subview id="subviewManterVenda">
	
		<script type="text/javascript">		
			function preencheDadosPopupCliente(codigo, descricao) {
				document.getElementById('subviewManterVenda:formVendaManter:venda_cliente_codigo').value = codigo;
				document.getElementById('subviewManterVenda:formVendaManter:venda_cliente_nome').value = descricao;
			}
			function preencheDadosPopupServico(codigo, descricao, tipo) {
				document.getElementById('subviewManterVenda:formVendaManter:venda_servico_codigo').value = codigo;
				document.getElementById('subviewManterVenda:formVendaManter:venda_servico_descricao').value = descricao;
			}
		</script>
		
		<rich:modalPanel id="manterVenda" autosized="true"  headerClass="height:100px;" resizeable="false" >
			<f:facet name="header">
				<h:outputText value="#{bundle.venda_titulo_manter}" />
			</f:facet>
			<f:facet name="controls">
				<h:panelGroup>
					<h:graphicImage value="/images/close.gif" styleClass="botao_fechar_popup" id="hideLink">
						<rich:componentControl for="manterVenda" attachTo="hideLink" operation="hide" event="onclick" />
					</h:graphicImage>
				</h:panelGroup>
			</f:facet>
			
			<div class="red">
				<rich:messages id="msgVendaConsultar"></rich:messages>
			</div>
			
			<a4j:form ajaxSubmit="true" id="formVendaManter" reRender="venda_cliente_codigo, venda_cliente_nome">
		  
		   <h:outputLabel value="#{bundle.venda_codigo}:" for="venda_codigo" />
           <h:inputText id="venda_codigo" value="#{vendaBackBean.vendaFormBean.vendaManter.codigo}"  label="#{bundle.venda_codigo}" disabled="#{true}" size="5" />
               
               <div class="linha"/>
               
		  <rich:panel>
		        
                <h:panelGrid columns="6">
                
                <h:outputLabel value="#{bundle.cliente_codigo}" for="cliente_codigo"/>
                <h:inputText id="venda_cliente_codigo" value="#{vendaBackBean.vendaFormBean.vendaManter.clienteVO.codigo}" label="#{bundle.venda_cliente_codigo}" disabled="#{true}" size="5"  />
                
                	  <h:outputLabel value="#{bundle.venda_cliente_nome}" for="venda_cliente_nome"/>
	                	<h:inputText id="venda_cliente_nome" value="#{vendaBackBean.vendaFormBean.vendaManter.clienteVO.nome}" label="#{bundle.venda_cliente_nome}" disabled="#{vendaBackBean.vendaFormBean.isDisabled}" size="40" maxlength="50" />
	                	
	                <a4j:commandButton value="#{bundle.venda_btn_popup}" id="btnPopupCliente" reRender="venda_cliente_codigo" disabled="#{vendaBackBean.vendaFormBean.isDisabled}">
	                	<rich:componentControl for="popupCliente" attachTo="btnPopupCliente" operation="show" event="onclick" />
	                </a4j:commandButton>
	            
                </h:panelGrid>
                	
                </rich:panel>	
            <rich:panel>
                 	
              <h:inputHidden id="venda_servico_codigo" value="#{vendaBackBean.vendaFormBean.servicoManter.codigo}" label="#{bundle.venda_servico_codigo}" />     	
                 	
         	<h:panelGrid columns="5">
               
				<h:outputLabel value="#{bundle.venda_servico}*:" for="venda_servico_descricao" />
				<h:inputText id="venda_servico_descricao" value="#{vendaBackBean.vendaFormBean.servicoManter.descricao}" label="#{bundle.venda_servico_descricao}" disabled="#{vendaBackBean.vendaFormBean.isDisabled}" size="30" />

	            <a4j:commandButton value="#{bundle.servico_btn_popup}" id="btnPopupServico" reRender="formVendaManter" disabled="#{vendaBackBean.vendaFormBean.isDisabled}">
	            	<rich:componentControl for="popupServico" attachTo="btnPopupServico" operation="show" event="onclick" />
	            </a4j:commandButton>
               
               	<h:outputLabel value="#{bundle.venda_qtd_pessoas}:" for="venda_qtd_pessoas" />
                <easy:inputMask id="venda_qtd_pessoas" value="#{carroBackBean.carroFormBean.carroManter.placa}"   required="false" submitWithMask="true"  mask="999" useMask="true" useValidate="true" useMaskSize="true" placeHolder="_" disabled="#{compraBackBean.compraFormBean.isDisabled}" size="9" />

 		 		
 		 		<h:outputLabel value="#{bundle.venda_dt_chegada}*:" for="venda_dt_chegada" />
                <rich:calendar id="venda_dt_chegada" inputStyle="width:5em" label="#{bundle.venda_dt_chegada}" disabled="#{compraBackBean.compraFormBean.isDisabled}" datePattern="dd/MM/yyyy" />
            
                <h:outputLabel value="#{bundle.venda_dt_saida}*:" for="venda_dt_saida" />
                <rich:calendar id="venda_dt_saida" inputStyle="width:5em" label="#{bundle.venda_dt_saida}" disabled="#{compraBackBean.compraFormBean.isDisabled}" datePattern="dd/MM/yyyy" />
                
				<a4j:commandButton action="#{vendaBackBean.listenerAddServico}" value="#{bundle.condicao_pagamento_btn_adicionar}" id="btnAdicionarServico" reRender="formVendaManter" disabled="#{vendaBackBean.vendaFormBean.isDisabled}" />

				</h:panelGrid>
			
           		</rich:panel>
           
	            <rich:panel>
	                     
	            <h:outputLabel value="#{bundle.venda_total}: #{VendaBackBean.vendaFormBean.vendaManter.total}" />
	              
	                <c:choose>
		                <c:when test="#{vendaBackBean.vendaFormBean.listaServicoManterSize == 0}" >
		                	<h:outputLabel value="#{bundle.condicao_pagamento_lista_vazia}"/>
		                </c:when>
		                
		                <c:otherwise>	                
	                		<h:outputLabel value="#{bundle.condicao_pagamento_porcentagem_total}: #{condicaoPagamentoBackBean.condicaoPagamentoFormBean.porcentagemTotal}%" />
	                		
	                		<div class="linha"/>
	                		
	                    	<rich:dataTable id="gridServico" var="Servico" value="#{VendaBackBean.vendaFormBean.listaServicoManter}"  rows="10" align="center" width="100%">
		                	
		                		<rich:column>
		                			<f:facet name="header">
		                				<h:outputLabel value="#{bundle.venda_servico_descricao}"/>
		                			</f:facet>
		                			<center>
		                				<h:outputLabel value="#{venda.dataCriacao}" />
		                			</center>
		                		</rich:column>
		                		
							<rich:column filterBy="#{venda.dataCriacao}">
									<f:facet name="header">
										<h:outputText value="#{bundle.venda_data_criacao}"/>
									</f:facet>
									<h:outputText value="#{venda.dataCriacao}">
										<f:convertDateTime pattern="dd/MM/yyyy" timeZone="America/Sao_Paulo" />
									</h:outputText>
							</rich:column>
							
							<rich:column filterBy="#{venda.dataAlteracao}">
								<f:facet name="header">
									<h:outputText value="#{bundle.venda_data_alteracao}"/>
								</f:facet>
								<h:outputText value="#{venda.dataAlteracao}">
									<f:convertDateTime pattern="dd/MM/yyyy" timeZone="America/Sao_Paulo" />
								</h:outputText>
							</rich:column>
							
		                	<rich:column>
		                			<f:facet name="header">
		                				<h:outputLabel value="#{bundle.venda_total}"/>
		                			</f:facet>
									<center>
		                				<h:outputLabel value="#{venda.servicoVO.valor}" />
		                			</center>
								</rich:column>		                		
		                	</rich:dataTable>
		                	
		                	<rich:datascroller id="dsGridServico" for="gridServico" renderIfSinglePage="true" maxPages="5" />
		                </c:otherwise>
		             </c:choose>
                </rich:panel>
                
                 <div class="linha"/>
                   
<!--              <h:outputLabel value="#{bundle.condicao_pagamento_forma_pagamento}*:" for="condicao_pagamento_forma_pagamento_descricao" />-->
	            
                <a4j:commandButton action="#{vendaBackBean.manterVenda}" value="#{bundle.venda_btn_gravar}" id="btnGravar"
                 reRender="formVendaManter" disabled="#{vendaBackBean.vendaFormBean.isDisabled}" />
                
                  <a4j:commandButton action="#{vendaBackBean.orcamentoVenda}" value="#{bundle.venda_btn_orcamento}" id="btnOrcamento"
                 reRender="gridVenda" disabled="#{vendaBackBean.vendaFormBean.isDisabled}" >
                	<rich:componentControl for="manterVenda" attachTo="btnorcamento" operation="hide" event="onclick" />
                </a4j:commandButton>
                
                <a4j:commandButton value="#{bundle.venda_btn_voltar}" id="btnVoltar" action="#{vendaBackBean.obterListaVenda}"
                  reRender="gridVenda" >
                	<rich:componentControl for="manterVenda" attachTo="btnVoltar" operation="hide" event="onclick" />
                </a4j:commandButton>
					
			</a4j:form>

		</rich:modalPanel>
		
	</f:subview>
	
	<ui:include src="/pages/cliente/popupCliente.xhtml" />
	<ui:include src="/pages/servico/popupServico.xhtml" />
</html>